package com.shenzhenai.composebasic.components

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

/**
 * @author huangzehui
 * @date 14/9/2025 下午10:37 周日
 * @description
 *
 *
 * DropdownMenu 用法
 * https://www.bilibili.com/video/BV1QL4y1M7EA?vd_source=e07cc8cc94eb22bd76722071b03cd199&spm_id_from=333.788.videopod.sections
 *
 */

@Composable
fun DropdownMenuSample() {

    var expend by remember {
        mutableStateOf(false)
    }

    Column() {
        Button(onClick = {
            expend = !expend
        }) {
            Text(text = "点击我")
        }


        DropdownMenu(expanded = expend, onDismissRequest = {
            expend = false
        }) {
            DropdownMenuItem(text = {
                Text(text = "menu item 1")
            }, onClick = {
                expend = false
            })


            DropdownMenuItem(text = {
                Text(text = "menu item 2")
            }, onClick = {
                expend = false
            })

            DropdownMenuItem(text = {
                Text(text = "menu item 3")
            }, onClick = {
                expend = false
            })
        }
    }
}

@Preview
@Composable
fun DropdownMenuSamplePreview() {
    DropdownMenuSample()
}